//
//  ViewController.m
//  CADisplayLinkDrawRect
//
//  Created by Xwoder on 17/1/31.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "ViewController.h"
#import "CircleView.h"

@interface ViewController ()

@property (nonatomic, weak) CircleView *cv;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    CircleView *cv = [[CircleView alloc] init];
    cv.backgroundColor = [UIColor darkGrayColor];
    cv.bounds = CGRectMake(0, 0, 300, 300);
    cv.center = self.view.center;
    cv.radius = 1;
    [self.view addSubview:cv];
    self.cv = cv;
    
    CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(refresh:)];
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}

- (void)refresh:(CADisplayLink *)displayLink {
    self.cv.radius += 1;
    
    if (self.cv.radius >= 140) {
        [displayLink invalidate];
    }
}

@end
